<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ClockInDayRecord extends Model
{
    use SoftDeletes;
    protected $table = 'clock_in_day_records';

    /**
     * 定义主键
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * 禁止批量赋值的字段
     *
     * @var array
     */
    protected $guarded = ['id','created_at','deleted_at'];

    /**
     * 软删除应该被调整为日期的属性
     * [$dates description]
     * @var [type]
     */
    protected $dates=[
        'created_at', 'updated_at','deleted_at'
    ];

    /**
     * 获得签到记录日期
     * @param string $start_time
     * @param string $end_time
     * @param int $userId
     * @param int $type 1每日规则，2累计规则
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
    public static function get_recode_day($start_time = '', $end_time = '', $userId = 0, $type = 1)
    {
        $query = self::query();
        $query->where('user_id', $userId);
        $query->where('type', $type);
        $query->where('day_time', '<=', $end_time);
        $query->where('day_time', '>=', $start_time);
        $query->orderBy('id', 'asc');
        $list = $query->select(['day_time'])->get()->toArray();

        return $list;
    }
}
